<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
       <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
       <%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<base href="<%=request.getContextPath()%>/">
		   
			<script type="text/javascript" src="js/public/jquery-2.1.1.min.js"></script>
		<style>
			.maintaince-list{
				width:400px;
				height: 300px;
				margin-left: 100px;
			}
			.oprate-m{
				width: 400px;
				height: 300px;
				margin-top: 10px;
				margin-left: 100px;
			}
		</style>
	</head>
	<body>
		<div class="maintaince-list">
			<table border="1px" cellspacing="" cellpadding="" width="100%" height="100%" id="tab">
				<tr>
					<th colspan="4">房间设施维护</th>
				</tr>
				<tr>
					<td>损坏描述</td>
					<td>报损日期</td>
					<td>是否解决</td>
					<td></td>
				</tr>
				<!-- 
				<tr>
					<td>厕所堵塞</td>
					<td>2012-09-09</td>
					<td>已解决</td>
				</tr>
				<tr>
					<td>水龙头开关坏</td>
					<td>2012-09-10</td>
					<td>已解决</td>
				</tr>
				<tr>
					<td>天然气炉盘不能打火</td>
					<td>2012-09-12</td>
					<td>未解决</td>
				</tr>
				 -->
			</table>
		</div>
		<div class="oprate-m">
			<table border="1px" cellspacing="" cellpadding="" width="100%" height="100%">
				<tr>
					<td>报损日期</td>
					<td colspan="2"><input type="date" name="" id="lossdate" value="" /></td>
				</tr>
			<tr>
				 <td>损坏描述</td>
				 <td colspan="2"><textarea rows="10" cols="30" id="errordesc">
				 	
				 </textarea></td>
			</tr>
				<tr>
				 <td>
				 <shiro:hasRole name="student">
				 <input type="button" name="" id="addLoss" value="添加设施损坏记录" />
				 </shiro:hasRole>
				 </td>
				 <shiro:hasRole name="landlord">
				 <td align="center"><input type="button" name="" id="repair" value="处理已损坏设施" /></td>
				 </shiro:hasRole>
				 <td align="right"></td>
			</tr>
				<tr>
				 <td colspan="3" id="info"></td>
			</tr>
			</table>
		</div>
	</body>
	<script type="text/javascript">
	//查看选择的房间设施
	$(function(){
		var rid=${param.rid};
		$.ajax({
			url:"repair/findLossByRid",
			type:"post",
			data:{"roomno":rid},
			success:function(data){
				//<tr>
				//<td>天然气炉盘不能打火</td>
				//<td>2012-09-12</td>
				//<td>未解决</td>
			//</tr>
			$.each(data,function(index,val){
				var table=$("#tab");
				var tr=$("<tr></tr>");
				var td1=$("<td></td>");
				td1.text(val.errordesc);
				var td2=$("<td></td>");
				td2.text(val.lossdate);
				var td3=$("<td></td>");
				if(val.issolve==1){
				td3.text("未解决");
				}
				else if(val.issolve==2){
					td3.text("已解决");
				}
				var td4=$("<td></td>");
				var input=$("<input type='radio' name='choice'></input>");
				input.val(val.id);
				td4.append(input);
				tr.append(td1);
				tr.append(td2);
				tr.append(td3);
				tr.append(td4);
				table.append(tr);
			})
		}
		});
		//添加设施损坏记录
		$("#addLoss").click(function(){
			var errordesc=$("#errordesc").val();
			var lossdate=$("#lossdate").val();
			if(errordesc.trim()==""){
				alert("损坏描述必须填写");
				return;
			}
			$.ajax({
				url:"repair/add",
				type:"post",
				data:{"roomno":rid,"errordesc":errordesc,"lossdate":lossdate},
				success:function(data){
					if(data==1){
						$("#info").html("<font color=green>添加成功</font>");
						window.location.reload();
					}
					else if(data==0){
						$("#info").html("<font color=red>添加失败</font>");
					}
					else if(data==-1){
						$("#info").html("<font color=red>当前房间无人居住不能添加损坏记录</font>");
					}
				}
			});
		});
		//处理已损坏设施
		$("#repair").click(function(){
			var repairId=$("#tab tr td input:checked").val();
			if(typeof(repairId)=="undefined"){
				alert("请选择您要处理的设施");
				return;
			}
			var isRepair=confirm("该设施确定处理好了吗?");
			if(!isRepair){
				return;
			}
			$.ajax({
				url:"repair/solve",
				data:{"id":repairId},
				type:"post",
				success:function(data){
					if(data>0){
					window.location.reload();
					}
				}
			})
		});
	})
	</script>
</html>
